package com.fanxuankai.ksql.function.udf.string;

import io.confluent.ksql.function.udf.Udf;
import io.confluent.ksql.function.udf.UdfDescription;
import io.confluent.ksql.function.udf.UdfParameter;
import org.apache.commons.lang3.StringUtils;

/**
 * 身份证号脱敏类型
 * 前3位，后4位
 * 130722199102323232 脱敏后: 130*************3232
 *
 * @author sixiaojie
 * @date 2022-06-25-15:22
 */
@UdfDescription(name = "id_card_mask", description = "id_card_mask", author = "sixiaojie")
public class IDCardMask {

    @Udf
    public String calc(@UdfParameter("val") String idCard) {
        if ((idCard == null || "".equals(idCard))) {
            return "";
        }

        return StringUtils.left(idCard, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(idCard, 4), StringUtils.length(idCard), "*"), "***"));
    }

}
